package com.api.shopapi.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {

    /**
     * 日期加一天
     * @param time
     * @return
     */
    public static String timeAddDay(String time,int day){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date time1 = null;
        try {
            time1 = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Calendar calendar = new GregorianCalendar();
        calendar.setTime(time1);
        calendar.add(calendar.DATE, day); //把日期往后增加一天,整数  往后推,负数往前移动
        time1 = calendar.getTime(); //这个时间就是日期往后推一天的结果

        String time2 = sdf.format(time1);
        return time2;
    }
}
